package com.internetCafes.spms.web.extend.controller;


import com.internetCafes.spms.common.CommonConstants;
import com.internetCafes.spms.common.base.BaseWebController;
import com.internetCafes.spms.core.model.pageModel.DataGrid;
import com.internetCafes.spms.core.utils.Query;
import com.internetCafes.spms.core.utils.R;
import com.internetCafes.spms.web.sys.model.ConfInfo;
import com.internetCafes.spms.web.sys.service.ConfInfoService;
import com.internetCafes.spms.web.sys.vo.ConfInfoVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LinYe
 * @since 2020-12-17
 */
@RestController
@RequestMapping("/cert/entQualiConf")
public class EntCertiQualiConfController extends BaseWebController {

    @Autowired
    ConfInfoService confInfoService;

    @PostMapping("/getQualifications")
    @RequiresPermissions("certificate:certificateInfo:list")
    public R getQualifications(@RequestBody Map<String, Object> params) {
        Query query = new Query(params);
        params.put("type", CommonConstants.CONF_QUALIFICATION_GRADE_TYPE);
        DataGrid dataGrid = confInfoService.dataGrid(params, query.getPage(), query.getLimit());
        List<ConfInfo> confInfoList = (List<ConfInfo>) dataGrid.getList();
        for (int i = 0, confInfoListSize = confInfoList.size(); i < confInfoListSize; i++) {
            ConfInfo confInfo = confInfoList.get(i);
            String name = confInfo.getName();
            ConfInfoVo confInfoVo = new ConfInfoVo();
            BeanUtils.copyProperties(confInfo, confInfoVo);
            confInfoVo.setLevels(CommonConstants.QualificationLevels.getLevels(name));

            confInfoList.set(i,confInfoVo);
        }
        dataGrid.setList(confInfoList);
        R r = R.ok().put("data", dataGrid);
        return r;
    }

}
